﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using GPSTrackingDBV2.Entities;
using GPSTrackingDBV2.Data;

#endregion

namespace GPSTrackingDBV2.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="ViewAdministratorByCompaniesProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class ViewAdministratorByCompaniesProviderBaseCore : EntityViewProviderBase<ViewAdministratorByCompanies>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;ViewAdministratorByCompanies&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;ViewAdministratorByCompanies&gt;"/></returns>
		protected static VList&lt;ViewAdministratorByCompanies&gt; Fill(DataSet dataSet, VList<ViewAdministratorByCompanies> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<ViewAdministratorByCompanies>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;ViewAdministratorByCompanies&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<ViewAdministratorByCompanies>"/></returns>
		protected static VList&lt;ViewAdministratorByCompanies&gt; Fill(DataTable dataTable, VList<ViewAdministratorByCompanies> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					ViewAdministratorByCompanies c = new ViewAdministratorByCompanies();
					c.Name = (Convert.IsDBNull(row["Name"]))?string.Empty:(System.String)row["Name"];
					c.Logo = (Convert.IsDBNull(row["Logo"]))?string.Empty:(System.String)row["Logo"];
					c.EncryptCompanyId = (Convert.IsDBNull(row["EncryptCompanyID"]))?string.Empty:(System.String)row["EncryptCompanyID"];
					c.AdminUsername = (Convert.IsDBNull(row["AdminUsername"]))?string.Empty:(System.String)row["AdminUsername"];
					c.Expr1 = (Convert.IsDBNull(row["Expr1"]))?string.Empty:(System.String)row["Expr1"];
					c.FirstName = (Convert.IsDBNull(row["FirstName"]))?string.Empty:(System.String)row["FirstName"];
					c.LastName = (Convert.IsDBNull(row["LastName"]))?string.Empty:(System.String)row["LastName"];
					c.Email = (Convert.IsDBNull(row["Email"]))?string.Empty:(System.String)row["Email"];
					c.Mobile = (Convert.IsDBNull(row["Mobile"]))?string.Empty:(System.String)row["Mobile"];
					c.Phone = (Convert.IsDBNull(row["Phone"]))?string.Empty:(System.String)row["Phone"];
					c.IsActive = (Convert.IsDBNull(row["IsActive"]))?false:(System.Boolean)row["IsActive"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;ViewAdministratorByCompanies&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;ViewAdministratorByCompanies&gt;"/></returns>
		protected VList<ViewAdministratorByCompanies> Fill(IDataReader reader, VList<ViewAdministratorByCompanies> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					ViewAdministratorByCompanies entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<ViewAdministratorByCompanies>("ViewAdministratorByCompanies",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new ViewAdministratorByCompanies();
					}
					
					entity.SuppressEntityEvents = true;

					entity.Name = (System.String)reader[((int)ViewAdministratorByCompaniesColumn.Name)];
					//entity.Name = (Convert.IsDBNull(reader["Name"]))?string.Empty:(System.String)reader["Name"];
					entity.Logo = (System.String)reader[((int)ViewAdministratorByCompaniesColumn.Logo)];
					//entity.Logo = (Convert.IsDBNull(reader["Logo"]))?string.Empty:(System.String)reader["Logo"];
					entity.EncryptCompanyId = (reader.IsDBNull(((int)ViewAdministratorByCompaniesColumn.EncryptCompanyId)))?null:(System.String)reader[((int)ViewAdministratorByCompaniesColumn.EncryptCompanyId)];
					//entity.EncryptCompanyId = (Convert.IsDBNull(reader["EncryptCompanyID"]))?string.Empty:(System.String)reader["EncryptCompanyID"];
					entity.AdminUsername = (System.String)reader[((int)ViewAdministratorByCompaniesColumn.AdminUsername)];
					//entity.AdminUsername = (Convert.IsDBNull(reader["AdminUsername"]))?string.Empty:(System.String)reader["AdminUsername"];
					entity.Expr1 = (System.String)reader[((int)ViewAdministratorByCompaniesColumn.Expr1)];
					//entity.Expr1 = (Convert.IsDBNull(reader["Expr1"]))?string.Empty:(System.String)reader["Expr1"];
					entity.FirstName = (System.String)reader[((int)ViewAdministratorByCompaniesColumn.FirstName)];
					//entity.FirstName = (Convert.IsDBNull(reader["FirstName"]))?string.Empty:(System.String)reader["FirstName"];
					entity.LastName = (System.String)reader[((int)ViewAdministratorByCompaniesColumn.LastName)];
					//entity.LastName = (Convert.IsDBNull(reader["LastName"]))?string.Empty:(System.String)reader["LastName"];
					entity.Email = (System.String)reader[((int)ViewAdministratorByCompaniesColumn.Email)];
					//entity.Email = (Convert.IsDBNull(reader["Email"]))?string.Empty:(System.String)reader["Email"];
					entity.Mobile = (reader.IsDBNull(((int)ViewAdministratorByCompaniesColumn.Mobile)))?null:(System.String)reader[((int)ViewAdministratorByCompaniesColumn.Mobile)];
					//entity.Mobile = (Convert.IsDBNull(reader["Mobile"]))?string.Empty:(System.String)reader["Mobile"];
					entity.Phone = (reader.IsDBNull(((int)ViewAdministratorByCompaniesColumn.Phone)))?null:(System.String)reader[((int)ViewAdministratorByCompaniesColumn.Phone)];
					//entity.Phone = (Convert.IsDBNull(reader["Phone"]))?string.Empty:(System.String)reader["Phone"];
					entity.IsActive = (System.Boolean)reader[((int)ViewAdministratorByCompaniesColumn.IsActive)];
					//entity.IsActive = (Convert.IsDBNull(reader["IsActive"]))?false:(System.Boolean)reader["IsActive"];
					entity.AcceptChanges();
					entity.SuppressEntityEvents = false;
					
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="ViewAdministratorByCompanies"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="ViewAdministratorByCompanies"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, ViewAdministratorByCompanies entity)
		{
			reader.Read();
			entity.Name = (System.String)reader[((int)ViewAdministratorByCompaniesColumn.Name)];
			//entity.Name = (Convert.IsDBNull(reader["Name"]))?string.Empty:(System.String)reader["Name"];
			entity.Logo = (System.String)reader[((int)ViewAdministratorByCompaniesColumn.Logo)];
			//entity.Logo = (Convert.IsDBNull(reader["Logo"]))?string.Empty:(System.String)reader["Logo"];
			entity.EncryptCompanyId = (reader.IsDBNull(((int)ViewAdministratorByCompaniesColumn.EncryptCompanyId)))?null:(System.String)reader[((int)ViewAdministratorByCompaniesColumn.EncryptCompanyId)];
			//entity.EncryptCompanyId = (Convert.IsDBNull(reader["EncryptCompanyID"]))?string.Empty:(System.String)reader["EncryptCompanyID"];
			entity.AdminUsername = (System.String)reader[((int)ViewAdministratorByCompaniesColumn.AdminUsername)];
			//entity.AdminUsername = (Convert.IsDBNull(reader["AdminUsername"]))?string.Empty:(System.String)reader["AdminUsername"];
			entity.Expr1 = (System.String)reader[((int)ViewAdministratorByCompaniesColumn.Expr1)];
			//entity.Expr1 = (Convert.IsDBNull(reader["Expr1"]))?string.Empty:(System.String)reader["Expr1"];
			entity.FirstName = (System.String)reader[((int)ViewAdministratorByCompaniesColumn.FirstName)];
			//entity.FirstName = (Convert.IsDBNull(reader["FirstName"]))?string.Empty:(System.String)reader["FirstName"];
			entity.LastName = (System.String)reader[((int)ViewAdministratorByCompaniesColumn.LastName)];
			//entity.LastName = (Convert.IsDBNull(reader["LastName"]))?string.Empty:(System.String)reader["LastName"];
			entity.Email = (System.String)reader[((int)ViewAdministratorByCompaniesColumn.Email)];
			//entity.Email = (Convert.IsDBNull(reader["Email"]))?string.Empty:(System.String)reader["Email"];
			entity.Mobile = (reader.IsDBNull(((int)ViewAdministratorByCompaniesColumn.Mobile)))?null:(System.String)reader[((int)ViewAdministratorByCompaniesColumn.Mobile)];
			//entity.Mobile = (Convert.IsDBNull(reader["Mobile"]))?string.Empty:(System.String)reader["Mobile"];
			entity.Phone = (reader.IsDBNull(((int)ViewAdministratorByCompaniesColumn.Phone)))?null:(System.String)reader[((int)ViewAdministratorByCompaniesColumn.Phone)];
			//entity.Phone = (Convert.IsDBNull(reader["Phone"]))?string.Empty:(System.String)reader["Phone"];
			entity.IsActive = (System.Boolean)reader[((int)ViewAdministratorByCompaniesColumn.IsActive)];
			//entity.IsActive = (Convert.IsDBNull(reader["IsActive"]))?false:(System.Boolean)reader["IsActive"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="ViewAdministratorByCompanies"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="ViewAdministratorByCompanies"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, ViewAdministratorByCompanies entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.Name = (Convert.IsDBNull(dataRow["Name"]))?string.Empty:(System.String)dataRow["Name"];
			entity.Logo = (Convert.IsDBNull(dataRow["Logo"]))?string.Empty:(System.String)dataRow["Logo"];
			entity.EncryptCompanyId = (Convert.IsDBNull(dataRow["EncryptCompanyID"]))?string.Empty:(System.String)dataRow["EncryptCompanyID"];
			entity.AdminUsername = (Convert.IsDBNull(dataRow["AdminUsername"]))?string.Empty:(System.String)dataRow["AdminUsername"];
			entity.Expr1 = (Convert.IsDBNull(dataRow["Expr1"]))?string.Empty:(System.String)dataRow["Expr1"];
			entity.FirstName = (Convert.IsDBNull(dataRow["FirstName"]))?string.Empty:(System.String)dataRow["FirstName"];
			entity.LastName = (Convert.IsDBNull(dataRow["LastName"]))?string.Empty:(System.String)dataRow["LastName"];
			entity.Email = (Convert.IsDBNull(dataRow["Email"]))?string.Empty:(System.String)dataRow["Email"];
			entity.Mobile = (Convert.IsDBNull(dataRow["Mobile"]))?string.Empty:(System.String)dataRow["Mobile"];
			entity.Phone = (Convert.IsDBNull(dataRow["Phone"]))?string.Empty:(System.String)dataRow["Phone"];
			entity.IsActive = (Convert.IsDBNull(dataRow["IsActive"]))?false:(System.Boolean)dataRow["IsActive"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region ViewAdministratorByCompaniesFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="ViewAdministratorByCompanies"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class ViewAdministratorByCompaniesFilterBuilder : SqlFilterBuilder<ViewAdministratorByCompaniesColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ViewAdministratorByCompaniesFilterBuilder class.
		/// </summary>
		public ViewAdministratorByCompaniesFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the ViewAdministratorByCompaniesFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public ViewAdministratorByCompaniesFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the ViewAdministratorByCompaniesFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public ViewAdministratorByCompaniesFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion ViewAdministratorByCompaniesFilterBuilder

	#region ViewAdministratorByCompaniesParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="ViewAdministratorByCompanies"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class ViewAdministratorByCompaniesParameterBuilder : ParameterizedSqlFilterBuilder<ViewAdministratorByCompaniesColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ViewAdministratorByCompaniesParameterBuilder class.
		/// </summary>
		public ViewAdministratorByCompaniesParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the ViewAdministratorByCompaniesParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public ViewAdministratorByCompaniesParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the ViewAdministratorByCompaniesParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public ViewAdministratorByCompaniesParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion ViewAdministratorByCompaniesParameterBuilder
	
	#region ViewAdministratorByCompaniesSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="ViewAdministratorByCompanies"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class ViewAdministratorByCompaniesSortBuilder : SqlSortBuilder<ViewAdministratorByCompaniesColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ViewAdministratorByCompaniesSqlSortBuilder class.
		/// </summary>
		public ViewAdministratorByCompaniesSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion ViewAdministratorByCompaniesSortBuilder

} // end namespace
